<?php
	require_once("htons-ntohs.php");

	 $uvbyte	= array(
		"char"	 => 1,
		"short"	 => 2,
		"uint32" => 4,
		"int"	 => 4,
		"uint64" => 8
	);

	class UVHEADER{
	public  $header	= array(
		"begin" => array(
			"type"  => "char",
			"value" => 2),		
		"len"	=> array(
			"type"  => "short",
			"value" => 0),
		"ver"	=> array(
			"type"  => "short",
			"value" => 1),
		"cmd"	=> array(
			"type"  => "short",
			"value" => 0),
		"reserve" => array(
			"type"  => "char",
			"value" => 0)
		);
	}


	class RspdInsertCmd{
	 public $rspdcmd	= array(
		"code"	=> array(
			"type"  => "int",
			"value" => 0),
		"end"	=> array(
			"type"	=> "char",
			"value" => 3)
		);
	}

	// 只是将传入数组的主机字节序转换为网络字节序
	function uvpack(&$data = array() /* IN OUT*/)
	{
		global $uvbyte;
		foreach($data as $k => $v)
		{
			htons($data[$k]["value"],$uvbyte[$v["type"]]);
		}
	}


	// 只是将传入数组的网络字节序转换为主机字节序
	function uvunpack(&$data = array() /* IN OUT*/)
	{
		global $uvbyte;
		foreach($data as $k => $v)
		{
			ntohs($data[$k]["value"],$uvbyte[$v["type"]]);
		}
	}

	//echo "hequan\n";
?>
